<!-- $Id -->

{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,validator.js"}
{if $step eq "consignee"}
{insert_scripts files="../js/region.js"}
{/if}
{insert_scripts files="../js/jquery.js"}
{if $step eq "user"}
<!-- 选择用户 -->

<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return checkUser()">
<div class="main-div" style="padding: 15px">
  <label><input type="radio" name="anonymous" value="1" checked /> {$lang.anonymous}</label><br />
  <label><input type="radio" name="anonymous" value="0" id="user_useridname" /> 按用户名，邮箱搜索</label>
  <input name="keyword" type="text" value="" />
  <input type="button" class="button" name="search" value="{$lang.button_search}" onclick="searchUser();" />
  <select name="user"></select>
</div>



<!-- 收货地址 -->


{insert_scripts files="../js/transport_org.js,../js/region.js"}
<script type="text/javascript">
region.isAdmin=true;
</script>

<div class="list-div">
<table cellpadding="3" cellspacing="1">
  {if $address_list}
  <tr>
    <th align="left">{$lang.address_list}</th>
    <td><select onchange="loadAddress(this.value)"><option value="0" selected>{$lang.select_please}</option>
      {foreach from=$address_list item=address}<option value="{$address.address_id}" {if $smarty.get.address_id eq $address.address_id}selected{/if}>{$address.consignee|escape} {$address.email} {$address.address|escape} {$address.tel|escape}</option>{/foreach}
    </select></td>
  </tr>
  {/if}
  <tr>
    <th width="150" align="left">收货人：</th>
    <td><input name="consignee" type="text" value="{$order.consignee}" />
      {$lang.require_field}</td>
  </tr>

  <tr>
    <th align="left">所在地区</th>
    <td>
      <select name="country" id="selCountries" onChange="region.changed(this, 1, 'selProvinces')">
        <option value="0" selected="true">{$lang.select_please}</option>
        {foreach from=$country_list item=country}
        <option value="{$country.region_id}" {if $order.country eq $country.region_id}selected{/if}>{$country.region_name}</option>
        {/foreach}
      </select> <select name="province" id="selProvinces" onChange="region.changed(this, 2, 'selCities')">
        <option value="0">{$lang.select_please}</option>
        {foreach from=$province_list item=province}
        <option value="{$province.region_id}" {if $order.province eq $province.region_id}selected{/if}>{$province.region_name}</option>
        {/foreach}
      </select> <select name="city" id="selCities" onchange="region.changed(this, 3, 'selDistricts')">
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$city_list item=city} -->
          <option value="{$city.region_id}" {if $order.city eq $city.region_id}selected{/if}>{$city.region_name}</option>
          <!-- {/foreach} -->
        </select>
        <select name="district" id="selDistricts" onchange="display_payment();"  >
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$district_list item=district} -->
          <option value="{$district.region_id}" {if $order.district eq $district.region_id}selected{/if}>{$district.region_name}</option>
          <!-- {/foreach} -->
        </select>
        {$lang.require_field}</td>
  </tr>


  <tr>
    <th align="left">详细地址</th>
    <td><input name="address" type="text" value="{$order.address}" size="40" />
    {$lang.require_field}</td>
  </tr>

  <tr>
    <th align="left">{$lang.label_mobile}</th>
    <td><input name="mobile" type="text" value="{$order.mobile}" /></td>
  </tr>
    <tr>
    <th align="left">订单来源</th>
    <td>
      <input type="radio" name="from_ad" value="1" />淘宝订单
      <input type="radio" name="from_ad" value="2" />商城订单
      <input type="radio" name="from_ad" value="3" />老师优惠
      <input type="radio" name="from_ad" value="5" />订单补发
    </td>
  </tr>
</table>
</div>
<script language="JavaScript">
function display_payment(){
  var obj = new Object;
  obj.province=document.getElementById("selProvinces").value;//获取省区值
  obj.city=document.getElementById("selCities").value;//获取市区值
  obj.district=document.getElementById("selDistricts").value;//获取地区值
  if(obj.district!=0){
  Ajax.call('order.php?act=add&step=user', 'consignee='+JSON.stringify(obj), paymentResponse, 'POST', 'JSON');
  }
}
// 返回选择支付方式
function paymentResponse(data){
  $('#payment').html(''); 
  $('#payment').html(data);
}





</script>
<div id="payment">

</div>







<div style="text-align:center">
  <p>
    <input name="submit" type="submit" class="button" value="{$lang.button_next}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</div>
</form>







{elseif $step eq "goods"}
<!-- 添加商品页面 -->
<div id="order_goods">



  <form name="theForm" action="order.php?act=step_post&step=edit_goods&order_id={$order_id}&step_act={$step_act}" method="post">
  <div class="list-div">
  <table cellpadding="3" cellspacing="1">
    <tr>
      <th scope="col">商品序号</th>
      <th scope="col">{$lang.goods_name}</th>
      <th scope="col">{$lang.goods_sn}</th>
      <th scope="col">{$lang.goods_price}</th>
      <th scope="col">{$lang.goods_number}</th>
      <th scope="col">{if $step_act eq add}库存{else}剩余库存{/if}</th>
      <th scope="col">{$lang.goods_attr}</th>
      <th scope="col">{$lang.subtotal}</th>
      <th scope="col">{$lang.handler}</th>
    </tr>
    {foreach from=$goods_list item=goods_list name="goods" key="key"}
    <tr>
      <td>{$key}</td>
      <td>
      {if $goods_list.goods_id gt 0 && $goods_list.extension_code neq 'package_buy'}
      <a href="#" onclick="getGoodsInfo({$goods.goods_id});">{$goods_list.goods_name}</a>
      {elseif $goods_list.goods_id gt 0 && $goods_list.extension_code eq 'package_buy'}
      {$goods_list.goods_name}
      {/if}
      </td>
      <td align="center">{$goods_list.goods_sku}<input name="rec_id[]" type="hidden" value="{$goods_list.rec_id}" /></td>
      <td align="center">

        {if $goods_list.is_gift eq 1 }
        赠品
        <input name="goods_price[]" type="hidden" style="text-align:right" value="{$goods_list.goods_price}" size="10" />
        <input name="goods_id[]" type="hidden" style="text-align:right" value="{$goods_list.goods_id}" size="10" />
        <td align="center"><input type="text"  disabled="disabled" style="text-align:right;{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' } color:#ff0000; {/if}     " value="{$goods_list.goods_number}" size="6" /><input name="goods_number[]" type="hidden" style="text-align:right;{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' }  color:#ff0000; {/if}     " value="{$goods_list.goods_number}" size="6" /></td>
        {else}

          {if  $goods_list.extension_code eq again}
        补发商品
        <input name="goods_price[]" type="hidden" style="text-align:right" value="{$goods_list.goods_price}" size="10" />
        <input name="goods_id[]" type="hidden" style="text-align:right" value="{$goods_list.goods_id}" size="10" />
        <td align="center"><input type="text"  disabled="disabled" style="text-align:right;{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' } color:#ff0000; {/if}     " value="{$goods_list.goods_number}" size="6" /><input name="goods_number[]" type="hidden" style="text-align:right;{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' }  color:#ff0000; {/if}     " value="{$goods_list.goods_number}" size="6" /></td>
          {else}
        <input name="goods_price[]" type="text" style="text-align:right" value="{$goods_list.goods_price}" size="10" />
        <input name="goods_id[]" type="hidden" style="text-align:right" value="{$goods_list.goods_id}" size="10" />
        <td align="center">
          <input name="goods_number[]" type="text" style="text-align:right;{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' }  color:#ff0000; {/if}     " value="{$goods_list.goods_number}" size="6" number="{$goods_list.goods_number}" stock="{$goods_list.goods_stock}" onkeyup="up_number(this);" /></td>
        {/if}

        {/if}
        




        </td>
      <td >{if ($goods_list.goods_number > $goods_list.goods_stock)&&$step_act!='edit' }  <span class="require-field">{$goods_list.goods_stock}</span>{else}{$goods_list.goods_stock}{/if}</td>
      <td align="center">{$goods_list.goods_attr}</td>
      <td align="right">{$goods_list.subtotal}</td>
      <td  align="center"><a href="javascript:confirm_redirect(confirm_drop, 'order.php?act=process&func=drop_order_goods&rec_id={$goods_list.rec_id}&step_act={$step_act}&order_id={$order_id}')">{$lang.drop}</a>
      {if $goods_list.extension_code neq again}
      <a onclick = 'remedy_goods({$goods_list.rec_id});'>标记为补发商品</a>
      {/if}
      {if $goods_list.extension_code eq again}
      <a onclick = ''>补发商品</a>
      {/if}
      </td>
    </tr>
    {/foreach}
    <tr>
      <td colspan="4"><span class="require-field" onclick="$('#consignee').toggle();">显示隐藏收货地址</span></td>
      <td colspan="2">商品数量总计<span style="font-size:20px;">{$count}</span></td>
      <td align="right"><strong>合计：</strong></td>
      <td align="right">{$goods_amount}{if $shipping_fee}  +运费：<input type="text" value="{$shipping_fee}" id="shipping_fee"  size="5">  
        <br/>共<span style="font-size:20px;">{$pay_fee}</span>
        {/if}
        {if $paid}
        <br/>已支付{$paid}
             还需要支付{$pay}
        {/if}
      </td>
      <td  align="center">{if $smarty.foreach.goods.total > 0}<input name="edit_goods" type="submit" value="{$lang.update_goods}" />{/if}
      <input name="goods_count" type="hidden" value="{$smarty.foreach.goods.total}" /></td>
    </tr>
  </table>
  </div>
  </form>
</div>

<!-- 标记补发商品-->
<script type="text/javascript">
  function remedy_goods(rec_id){
      Ajax.call('order.php?act=remedy_goods&order_id={$order_id}', 'rec_id='+rec_id, remedy_goods_return, 'POST', 'JSON');

  }

function remedy_goods_return(date){



  if(date== 1){
    window.location.reload(); 
  }



}






</script>







<!-- 收货人信息 -->
{insert_scripts files="../js/transport_org.js,../js/region.js"}
<script type="text/javascript">
region.isAdmin=true;
</script>

<div class="list-div" id="consignee" style="display:none">
<table cellpadding="3" cellspacing="1">
  <tr>
    <th width="150" align="left">收货人：</th>
    <td><input name="consignee" type="text" id="order_consignee" value="{$order.consignee}" />
      {$lang.require_field}</td>
  </tr>

  <tr>
    <th align="left">所在地区</th>
    <td>
      <select name="country" id="selCountries" onChange="region.changed(this, 1, 'selProvinces')">
        <option value="0" selected="true">{$lang.select_please}</option>
      <!--   {foreach from=$country_list item=country} -->
        <option value="{$country.region_id}" {if $order.country eq $country.region_id}selected{/if}>{$country.region_name}</option>
      <!--   {/foreach} -->
      </select> <select name="province" id="selProvinces" onChange="region.changed(this, 2, 'selCities')">
        <option value="0">{$lang.select_please}</option>
       <!--  {foreach from=$province_list item=province} -->
        <option value="{$province.region_id}" {if $order.province eq $province.region_id}selected{/if}>{$province.region_name}</option>
        <!-- {/foreach} -->
      </select> <select name="city" id="selCities" onchange="region.changed(this, 3, 'selDistricts')">
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$city_list item=city} -->
          <option value="{$city.region_id}" {if $order.city eq $city.region_id}selected{/if}>{$city.region_name}</option>
          <!-- {/foreach} -->
        </select>
        <select name="district" id="selDistricts" onchange="display_payment();"  >
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$district_list item=district} -->
          <option value="{$district.region_id}" {if $order.district eq $district.region_id}selected{/if}>{$district.region_name}</option>
          <!-- {/foreach} -->
        </select>
        {$lang.require_field}</td>
  </tr>


  <tr>
    <th align="left">详细地址</th>
    <td><input name="address" type="text" id="address" value="{$order.address}" size="40" />
    {$lang.require_field}</td>
  </tr>

  <tr>
    <th align="left">{$lang.label_mobile}</th>
    <td><input name="mobile" type="text" id="mobile" value="{$order.mobile}" />
      <div style="float:right; margin-right:50px;" onclick="up_address()">更新收货地址</div></td>
  </tr>
</table>
</div>
<script language="JavaScript">
// 更新收货地址
function up_address(){
  var obj = new Object;
  obj.province=document.getElementById("selProvinces").value;//获取省区值
  obj.city=document.getElementById("selCities").value;//获取市区值
  obj.district=document.getElementById("selDistricts").value;//获取地区值
  obj.address=document.getElementById("address").value;//详细地址
  obj.mobile=document.getElementById("mobile").value;//电话号码
  obj.order_consignee=document.getElementById("order_consignee").value;//收货人名称
  if(obj.district!=0){
  Ajax.call('order.php?act=up_address&order_id={$order_id}', 'consignee='+JSON.stringify(obj), up_address_Response, 'POST', 'JSON');
  }
}
function up_address_Response(data){
  alert(data);
}
</script>




<!-- 兑换刮蛋乐 -->
<form  action="order.php?act=award_exchange&order_id={$order_id}" method="post" onsubmit="return award_exchange()" >
<div >刮蛋乐 <input type="text" name="cdkey" id="cdkey"><input type="submit" value="兑换"></div>
  <script language="JavaScript">
  // 兑换刮蛋乐
  function award_exchange(){  
    var cdkey=$('#cdkey').val();//获取省区值
    if(cdkey!=0){
    Ajax.call('order.php?act=award_exchange&order_id={$order_id}', 'cdkey='+cdkey, award_exchange_Response, 'POST', 'JSON');
    }
    return false;
  }
  function award_exchange_Response(data){
    if(data.error==1){
      alert(data.message);
    }
    else{
       alert(data.message);
       window.location.reload();
    }



  }
  </script>
</form>
<!-- 生成补发单 -->

<div style='margin-top:10px;'>
  补发订单号 <input type="text" class="order_sn_old">
  补发原因  <select name="" id="remedy_type">
    <option value="1">商品错发</option>
    <option value="2">商品漏发</option>
  </select>
<input type="submit" onclick='order_remedy_is();' value="生成补发单">

  <script language="JavaScript">
  // 兑换刮蛋乐
function order_remedy_is(){
  //查询改订单号是否有补发单


  var order_sn_old = $('.order_sn_old').val();
  Ajax.call('order.php?act=is_remedy', 'order_sn_old='+order_sn_old, is_remedy_Response, 'POST', 'JSON');


}
function is_remedy_Response(data){
  if(data.error == 1){
    order_remedy();
  }
  if(data.error == 2){
   
    if(confirm(data.content)){
   order_remedy();
    }


 
  }



}





  function order_remedy(){  
    var remedy_type = $('#remedy_type').val();
    var order_sn_old = $('.order_sn_old').val();
    Ajax.call('order.php?act=order_remedy&order_id={$order_id}', 'remedy_type='+remedy_type+'&order_sn_old='+order_sn_old, order_remedy_Response, 'POST', 'JSON');
  }
  function order_remedy_Response(data){
    alert(data.content);
  }
  </script>
</div>




<form name="goodsForm" action="order.php?act=step_post&step=add_goods&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return addToOrder()">
<p>
  {$lang.search_goods}
  <input type="text" name="keyword" value="" />
  <input type="button" name="search" value="{$lang.button_search}" onclick="searchGoods();" />
  <select name="goodslist" id ="goodslist" onchange="getGoodsInfo(this.value)"></select>
</p>

<div id="order_goods_info">
  <div class="list-div">
    <!--   商品信息 -->
    <table cellpadding="3" cellspacing="1">
      <tr>
        <th width="100">商品名称</th>
        <td id="goods_name">{$goods.goods_name}</td>
      </tr>
      <tr>
        <th>商品编号</th>
        <td id="goods_sku">{$goods.goods_sku}</td>
      </tr>
      <tr class='none'>
        <th>商品分类</th>
        <td id="goods_cat">{$goods.cat_name}</td>
      </tr>
      <tr class='none'>
        <th>商品品牌</th>
        <td id="goods_brand">{$goods.brand_name}</td>
      </tr>
      <tr>
        <th>商品价格</th>
          <td id="add_price">
            <input type="radio" name="add_price"  value="{$goods.market_price}">市场价 [{$goods.market_price}]<br>
            <input type="radio" name="add_price" value="{$goods.shop_price}" checked>本店价 [{$goods.shop_price}]<br>
            <input type="radio" name="add_price" value="{$goods.preferential_price2}">梯度3价 [{$goods.preferential_price}]<br>
            <input type="radio" name="add_price" value="user_input">自定义价格<input type="text" name="input_price" value=""><br>
          </td>
      </tr>
<!--       最组合包含商品 -->
      {if $goods.compose}
      <tr>
        <th>最组合包含商品 <br/>
          <span onclick="$('.compose_stock').toggle();">显示库存</span></th>
        <td >
           {foreach from=$goods.compose item=compose}
            <div style="width:500px; float: left;">{$compose.goods_name} <span style="color:#b81b1b">{$compose.goods_number}</span></div>  
            <span class="compose_stock" {if $compose.goods_stock eq 0 } style="color:#bd0707"      {/if }>库存（{$compose.goods_stock}）</span>
            <br/>
          {/foreach}
        </td>
      </tr>
      {/if}

      <!-- 最组合属性 -->
      {if $goods.compose_attr}
      <tr>
        <th>最组合可选颜色
          <br/>
          <span style="color:#b81b1b; font-size:20px;">选择{$goods.compose_color_num}种颜色</span>
          <br/>
          已选择<span id="compose_color_number">0</span>种颜色
          <br/>
          <span class="name_list"></span>
        </th>
        <td id="goods_attr">
          <input type="hidden" value="{$goods.compose_note}" name="compose_note">
           {foreach from=$goods.compose_attr item=attr}
            <div style="width:160px; float:left" class="compose_color_num"><input type="text" name="attr[{$attr.attr_sku}]" style="width:40px;" onblur="up_num();" onchange="stock(this);" ><span class='color_name'>{$attr.attr_value}</span> <span style="color:#b81b1b" class="stock">{$attr.goods_stock}</span></div>
          {/foreach}
        </td>
      </tr>
  <script language="JavaScript">
  function up_num(){
      var new_num=0;
      var name_list='';
      $('.compose_color_num').each(function(){

            var num=parseInt($(this).find('input').val());
            var name=$(this).find('.color_name').html();
                if(num>0){
                  new_num=new_num+num;
                  name_list=name+'*'+num+"<br/>"+name_list;
                  $('.name_list').html(name_list);
                  $('#compose_color_number').html(new_num);
                }            
          });
  }
</script>
      {/if}
      <!-- 单品属性 -->
      {if $goods.attr_list}
      <tr>
        <th>商品属性<input type="hidden" name="spec_count" value="0" /></th>
        <td id="goods_attr">
           {foreach from=$goods.attr_list item=attr}
           <div style="width:160px; float:left"> <input type="text" name="attr[{$attr.attr_sku}]" style="width:40px;" onchange="stock(this);" >{$attr.attr_value} <span style="color:#b81b1b" class="stock">{$attr.attr_stock}</span></div>
          {/foreach}
        </td>
      </tr>
      {else}
      <tr>
        <th>商品库存</th>
        <td>{$goods.goods_stock}</td>
      </tr>
      <tr>
        <th>{$lang.goods_number}</th>
        <td><input name="add_number" type="text" value="1" id="add_number" size="10" {if $from_ad neq 1} onkeyup="up_price(this);" {/if}></td>
      </tr>
      {/if}
      <tr>
        <td colspan="2" align="center"><input name="add_goods" type="submit" value="加入订单" /></td>
      </tr>
    </table>
    </div>
</div>
</form>

<!-- 完成订单按钮 -->
{if $step_act eq add}
<form action="order.php?act=order_confirm&sign={$smarty.get.sign}" method="post" onsubmit="return order_confirm();">
  <p align="center">
    <input name="finish" type="submit" class="button" value="完成订单" />
    <input name="order_id" type="hidden"  value="{$order_id}">
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
<script language="JavaScript">
//根据数量选价格
function up_price(obj){
  var number=parseInt($(obj).val());
  if(number>=3){
      $('#add_price').find('input').eq(2).attr("checked",true);
  }
}

function order_confirm(){
  shipping_fee=document.getElementById("shipping_fee")?document.getElementById("shipping_fee").value:0;
  Ajax.call('order.php?act=order_confirm&order_id={$order_id}&sign={$smarty.get.sign}', 'shipping_fee='+shipping_fee, order_confirm_return, 'POST', 'JSON');
  return false;
}
// 订单是否成功
function order_confirm_return(data){
  if(data.error==0){
    alert(data.message);
    alert(data.number);
  }
  if(data.error==1){
    alert(data.message);
    window.location.href="order.php?act=list"; 
  }
  return false;
}





</script>

</form>
{else}
<form action="order.php?act=order_confirm&sign={$smarty.get.sign}" method="post" onsubmit="return order_edit()">
  <p align="center">
    <input name="finish" type="submit" class="button" value="完成订单" />
    <input name="order_id" type="hidden"  value="{$order_id}">
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
<script language="JavaScript">
//根据数量选价格
function up_price(obj){
  var number=parseInt($(obj).val());
  if(number>1&&number<4){
      $('#add_price').find('input').eq(2).attr("checked",true);
  }
  if(number>4){
      $('#add_price').find('input').eq(3).attr("checked",true);
  }
}

function order_edit(){
  document.getElementById("shipping_fee")?shipping_fee=document.getElementById("shipping_fee").value:shipping_fee=0;
  Ajax.call('order.php?act=order_edit&order_id={$order_id}', 'shipping_fee='+shipping_fee, order_edit_return, 'POST', 'JSON');
return false;
}
// 订单是否成功编辑
function order_edit_return(data){
  if(data.error==0){
    alert(data.message);
    alert(data.number);
    return false;
  }
  if(data.error==1){
    alert(data.message);
    window.location.href="order.php?act=list"; 
  }
}
</script>
</form>
{/if}
{elseif $step eq "consignee"}
{insert_scripts files="../js/transport_org.js,../js/region.js"}
<script type="text/javascript">
region.isAdmin=true;
</script>
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return checkConsignee()">
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  {if $address_list}
  <tr>
    <th align="left">{$lang.address_list}</th>
    <td><select onchange="loadAddress(this.value)"><option value="0" selected>{$lang.select_please}</option>
      {foreach from=$address_list item=address}<option value="{$address.address_id}" {if $smarty.get.address_id eq $address.address_id}selected{/if}>{$address.consignee|escape} {$address.email} {$address.address|escape} {$address.tel|escape}</option>{/foreach}
    </select></td>
  </tr>
  {/if}
  <tr>
    <th width="150" align="left">{$lang.label_consignee}</th>
    <td><input name="consignee" type="text" value="{$order.consignee}" />
      {$lang.require_field}</td>
  </tr>
  {if $exist_real_goods}
  <tr>
    <th align="left">{$lang.label_area}</th>
    <td><select name="country" id="selCountries" onChange="region.changed(this, 1, 'selProvinces')">
        <option value="0" selected="true">{$lang.select_please}</option>
        {foreach from=$country_list item=country}
        <option value="{$country.region_id}" {if $order.country eq $country.region_id}selected{/if}>{$country.region_name}</option>
        {/foreach}
      </select> <select name="province" id="selProvinces" onChange="region.changed(this, 2, 'selCities')">
        <option value="0">{$lang.select_please}</option>
        {foreach from=$province_list item=province}
        <option value="{$province.region_id}" {if $order.province eq $province.region_id}selected{/if}>{$province.region_name}</option>
        {/foreach}
      </select> <select name="city" id="selCities" onchange="region.changed(this, 3, 'selDistricts')">
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$city_list item=city} -->
          <option value="{$city.region_id}" {if $order.city eq $city.region_id}selected{/if}>{$city.region_name}</option>
          <!-- {/foreach} -->
        </select>
        <select name="district" id="selDistricts">
          <option value="0">{$lang.select_please}</option>
          <!-- {foreach from=$district_list item=district} -->
          <option value="{$district.region_id}" {if $order.district eq $district.region_id}selected{/if}>{$district.region_name}</option>
          <!-- {/foreach} -->
        </select>
        {$lang.require_field}</td>
  </tr>
  {/if}
  <tr>
    <th align="left">{$lang.label_email}</th>
    <td><input name="email" type="text" value="{$order.email}" size="40" />
    {$lang.require_field}</td>
  </tr>
  {if $exist_real_goods}
  <tr>
    <th align="left">{$lang.label_address}</th>
    <td><input name="address" type="text" value="{$order.address}" size="40" />
    {$lang.require_field}</td>
  </tr>
  <tr>
    <th align="left">{$lang.label_zipcode}</th>
    <td><input name="zipcode" type="text" value="{$order.zipcode}" /></td>
  </tr>
  {/if}
  <tr>
    <th align="left">{$lang.label_tel}</th>
    <td><input name="tel" type="text" value="{$order.tel}" />
    {$lang.require_field}</td>
  </tr>
  <tr>
    <th align="left">{$lang.label_mobile}</th>
    <td><input name="mobile" type="text" value="{$order.mobile}" /></td>
  </tr>
  {if $exist_real_goods}
  <tr>
    <th align="left">{$lang.label_sign_building}</th>
    <td><input name="sign_building" type="text" value="{$order.sign_building}" size="40" /></td>
  </tr>
  <tr>
    <th align="left">{$lang.label_best_time}</th>
    <td><input name="best_time" type="text" value="{$order.best_time}" size="40" /></td>
  </tr>
  {/if}
</table>
</div>

<div align="center">
  <p>
    {if $step_act eq "add"}{if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}{/if}
    <input name="{if $step_act eq 'add'}next{else}finish{/if}" type="submit" class="button" value="{if $step_act eq 'add'}{$lang.button_next}{else}{$lang.button_submit}{/if}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</div>
</form>

{elseif $step eq "shipping"}
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return checkShipping()">
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  <tr>
    <th width="5%">&nbsp;</th>
    <th width="25%">{$lang.name}</th>
    <th>{$lang.desc}</th>
    <th width="15%">{$lang.shipping_fee}</th>
    <th width="15%">{$lang.free_money}</th>
  <th width="15%">{$lang.insure}</th>
  </tr>
  {foreach from=$shipping_list item=shipping}
  <tr>
    <td><input name="shipping" type="radio" value="{$shipping.shipping_id}" {if $order.shipping_id eq $shipping.shipping_id}checked{/if} onclick="" /></td>
    <td>{$shipping.shipping_name}</td>
    <td>{$shipping.shipping_desc}</td>
    <td><div align="right">{$shipping.format_shipping_fee}</div></td>
    <td><div align="right">{$shipping.free_money}</div></td>
  <td><div align="right">{$shipping.insure}</div></td>
  </tr>
  {/foreach}
</table>
</div>

<p align="right"><input name="insure" type="checkbox" value="1" {if $order.insure_fee > 0}checked{/if} />
{$lang.want_insure}</p>

  <p align="center">
    {if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}
    <input name="{if $step_act eq 'add'}next{else}finish{/if}" type="submit" class="button" value="{if $step_act eq 'add'}{$lang.button_next}{else}{$lang.button_submit}{/if}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</form>

{elseif $step eq "payment"}
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return checkPayment()">
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  <tr>
    <th width="5%">&nbsp;</th>
    <th width="20%">{$lang.name}</th>
    <th>{$lang.desc}</th>
    <th width="15%">{$lang.pay_fee}</th>
  </tr>
  {foreach from=$payment_list item=payment}
  <tr>
    <td><input type="radio" name="payment" value="{$payment.pay_id}" {if $order.pay_id eq $payment.pay_id}checked{/if} /></td>
    <td>{$payment.pay_name}</td>
    <td>{$payment.pay_desc}</td>
    <td align="right">{$payment.pay_fee}</td>
  </tr>
  {/foreach}
</table>
</div>
  <p align="center">
    {if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}
    <input name="{if $step_act eq 'add'}next{else}finish{/if}" type="submit" class="button" value="{if $step_act eq 'add'}{$lang.button_next}{else}{$lang.button_submit}{/if}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</form>

{elseif $step eq "other"}
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post">
<div class="list-div">
{if $exist_real_goods and ($pack_list or $card_list)}
<table cellpadding="3" cellspacing="1">
  {if $pack_list}
  <tr>
    <th colspan="4" scope="col">{$lang.select_pack}</th>
    </tr>
  <tr>
    <td width="5%" scope="col">&nbsp;</td>
    <td width="35%" scope="col"><div align="center"><strong>{$lang.name}</strong></div></td>
    <td width="22%" scope="col"><div align="center"><strong>{$lang.pack_fee}</strong></div></td>
    <td width="22%" scope="col"><div align="center"><strong>{$lang.free_money}</strong></div></td>
    </tr>
  <tr>
    <td><input type="radio" name="pack" value="0" {if $order.pack_id eq 0}checked{/if} /></td>
    <td>{$lang.no_pack}</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  {foreach from=$pack_list item=pack}
  <tr>
    <td><input type="radio" name="pack" value="{$pack.pack_id}" {if $order.pack_id eq $pack.pack_id}checked{/if} /></td>
    <td>{$pack.pack_name}</td>
    <td><div align="right">{$pack.format_pack_fee}</div></td>
    <td><div align="right">{$pack.format_free_money}</div></td>
    </tr>
  {/foreach}
  {/if}
  {if $card_list}
  <tr>
    <th colspan="4" scope="col">{$lang.select_card}</th>
    </tr>
  <tr>
    <td scope="col">&nbsp;</td>
    <td scope="col"><div align="center"><strong>{$lang.name}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.card_fee}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.free_money}</strong></div></td>
    </tr>
  <tr>
    <td><input type="radio" name="card" value="0" {if $order.card_id eq 0}checked{/if} /></td>
    <td>{$lang.no_card}</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  {foreach from=$card_list item=card}
  <tr>
    <td><input type="radio" name="card" value="{$card.card_id}" {if $order.card_id eq $card.card_id}checked{/if} /></td>
    <td>{$card.card_name}</td>
    <td><div align="right">{$card.format_card_fee}</div></td>
    <td><div align="right">{$card.format_free_money}</div></td>
    </tr>
  {/foreach}
  {/if}
</table>
{/if}
</div><br />
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  {if $exist_real_goods}
  {if $card_list}
  <tr>
    <th>{$lang.label_card_message}</th>
    <td><textarea name="card_message" cols="60" rows="3">{$order.card_message}</textarea></td>
  </tr>
  {/if}
  <tr>
    <th>{$lang.label_inv_type}</th>
    <td><input name="inv_type" type="text" id="inv_type" value="{$order.inv_type}" size="40" /></td>
  </tr>
  <tr>
    <th>{$lang.label_inv_payee}</th>
    <td><input name="inv_payee" value="{$order.inv_payee}" size="40" text="text" /></td>
  </tr>
  <tr>
    <th>{$lang.label_inv_content}</th>
    <td><input name="inv_content" value="{$order.inv_content}" size="40" text="text" /></td>
  </tr>
  {/if}
  <tr>
    <th>{$lang.label_postscript}</th>
    <td><textarea name="postscript" cols="60" rows="3">{$order.postscript}</textarea></td>
  </tr>
  <tr>
    <th>{$lang.label_how_oos}</th>
    <td><input name="how_oos" type="text" value="{$order.how_oos}" size="40" /></td>
  </tr>
  <tr>
    <th>{$lang.label_to_buyer}</th>
    <td><textarea name="to_buyer" cols="60" rows="3">{$order.to_buyer}</textarea></td>
  </tr> 
</table>
</div>
  <p align="center">
    {if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}
    <input name="{if $step_act eq 'add'}next{else}finish{/if}" type="submit" class="button" value="{if $step_act eq 'add'}{$lang.button_next}{else}{$lang.button_submit}{/if}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</form>

{elseif $step eq "money"}
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post">
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  <tr>
    <th width="120">{$lang.label_goods_amount}</th>
    <td width="150">{$order.formated_goods_amount}</td>
  <th width="120">{$lang.label_discount}</th>
    <td><input name="discount" type="text" id="discount" value="{$order.discount}" size="15" /></td>
  </tr>
  <tr>
    <th>{$lang.label_tax}</th>
    <td><input name="tax" type="text" id="tax" value="{$order.tax}" size="15" /></td>
    <th>{$lang.label_order_amount}</th>
    <td>{$order.formated_total_fee}</td>
  </tr>
  <tr>
    <th>{$lang.label_shipping_fee}</th>
    <td>{if $exist_real_goods}<input name="shipping_fee" type="text" value="{$order.shipping_fee}" size="15">{else}0{/if}</td>
  <th width="120">{$lang.label_money_paid}</th>
    <td>{$order.formated_money_paid} </td>
  </tr>
  <tr>
    <th>{$lang.label_insure_fee}</th>
    <td>{if $exist_real_goods}<input name="insure_fee" type="text" value="{$order.insure_fee}" size="15">{else}0{/if}</td>
  <th>{$lang.label_surplus}</th>
    <td>{if $order.user_id >0}
        <input name="surplus" type="text" value="{$order.surplus}" size="15">
  {/if} {$lang.available_surplus}{$available_user_money|default:0}</td>
  </tr>
  <tr>
    <th>{$lang.label_pay_fee}</th>
    <td><input name="pay_fee" type="text" value="{$order.pay_fee}" size="15"></td>
  <th>{$lang.label_integral}</th>
    <td>{if $order.user_id > 0}
        <input name="integral" type="text" value="{$order.integral}" size="15">
  {/if} {$lang.available_integral}{$available_pay_points|default:0}</td>
  </tr>
  <tr>
    <th>{$lang.label_pack_fee}</th>
    <td>{if $exist_real_goods}
      <input name="pack_fee" type="text" value="{$order.pack_fee}" size="15">
      {else}0{/if}</td>
    <th>{$lang.label_bonus}</th>
    <td>
      <select name="bonus_id">
        <option value="0" {if $order.bonus_id eq 0}selected{/if}>{$lang.select_please}</option>

          {foreach from=$available_bonus item=bonus}

        <option value="{$bonus.bonus_id}" {if $order.bonus_id eq $bonus.bonus_id}selected{/if} money="{$bonus.type_money}">{$bonus.type_name} - {$bonus.type_money}</option>

          {/foreach}

      </select>    </td>
  </tr>
  <tr>
    <th>{$lang.label_card_fee}</th>
    <td>{if $exist_real_goods}
      <input name="card_fee" type="text" value="{$order.card_fee}" size="15">
      {else}0{/if}</td>
    <th>{if $order.order_amount >= 0} {$lang.label_money_dues} {else} {$lang.label_money_refund} {/if}</th>
    <td>{$order.formated_order_amount}</td>
  </tr>
</table>
</div>
  <p align="center">
    {if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}
    <input name="finish" type="submit" class="button" value="{$lang.button_finish}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</form>

{elseif $step eq "invoice"}
<form name="theForm" action="order.php?act=step_post&step={$step}&order_id={$order_id}&step_act={$step_act}" method="post" onsubmit="return checkShipping()">
<div class="list-div">
<table cellpadding="3" cellspacing="1">
  <tr>
    <th width="5%">&nbsp;</th>
    <th width="25%">{$lang.name}</th>
    <th>{$lang.desc}</th>
    </tr>
  {foreach from=$shipping_list item=shipping}
  <tr>
    <td><input name="shipping" type="radio" value="{$shipping.shipping_id}" {if $order.shipping_id eq $shipping.shipping_id}checked{/if} onclick="" /></td>
    <td>{$shipping.shipping_name}</td>
    <td>{$shipping.shipping_desc}</td>
    </tr>
  {/foreach}
  <tr>
    <td colspan="3"><strong>{$lang.shipping_note}</strong></td>
    </tr>
  <tr>
    <td colspan="3"><a href="javascript:showNotice('noticeinvoiceno');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a><strong>{$lang.label_invoice_no}</strong><input name="invoice_no" type="text" value="{$order.invoice_no}" size="30" autofocus/><br/><span class="notice-span" id="noticeinvoiceno" style="display:block;">{$lang.invoice_no_mall}</span></td>
  </tr>
</table>
</div>

  <p align="center">
    {if $step_act eq "add"}<input type="button" value="{$lang.button_prev}" class="button" onclick="history.back()" />{/if}
    <input name="{if $step_act eq 'add'}next{else}finish{/if}" type="submit" class="button" value="{if $step_act eq 'add'}{$lang.button_next}{else}{$lang.button_submit}{/if}" />
    <input type="button" value="{$lang.button_cancel}" class="button" onclick="location.href='order.php?act=process&func=cancel_order&order_id={$order_id}&step_act={$step_act}'" />
  </p>
</form>
{/if}

<script language="JavaScript">
  var step = '{$step}';
  var orderId = {$order_id};
  var act = '{$smarty.get.act}';
{literal}
  function checkUser()
  {
    var eles = document.forms['theForm'].elements;

    /* 如果搜索会员，检查是否找到 */
    if (document.getElementById('user_useridname').checked && eles['user'].options.length == 0)
    {
      alert(pls_search_user);
      return false;
    }
    return true;
  }
  //提示商品库存
  function stock(data){
      var num=parseInt($(data).val());
      var stock= parseInt($(data).siblings('.stock').html());
      if(num>stock){
        alert('该商品库存只有'+stock+'个');
      }
  }
  //判断更新商品输出数量是否大于库存
function up_number(obj){

  var number=parseInt($(obj).val());//输入数量
  var number_old=parseInt($(obj).attr('number'));//输入数量
  var stock=parseInt($(obj).attr('stock'));//剩余库存
  if(number>(number_old+stock)){
    alert('你输入的数量超过库存');
  }
}



  function checkGoods()
  {
    var eles = document.forms['theForm'].elements;

    if (eles['goods_count'].value <= 0)
    {
      alert(pls_search_goods);
      return false;
    }
    return true;
  }

  function checkConsignee()
  {
    var eles = document.forms['theForm'].elements;

    if (eles['country'].value <= 0)
    {
      alert(pls_select_area);
      return false;
    }
    if (eles['province'].options.length > 1 && eles['province'].value <= 0)
    {
      alert(pls_select_area);
      return false;
    }
    if (eles['city'].options.length > 1 && eles['city'].value <= 0)
    {
      alert(pls_select_area);
      return false;
    }
    if (eles['district'].options.length > 1 && eles['district'].value <= 0)
    {
      alert(pls_select_area);
      return false;
    }
    return true;
  }

  function checkShipping()
  {
    if (!radioChecked('shipping'))
    {
      alert(pls_select_shipping);
      return false;
    }
    return true;
  }

  function checkPayment()
  {
    if (!radioChecked('payment'))
    {
      alert(pls_select_payment);
      return false;
    }
    return true;
  }

  /**
   * 返回某 radio 是否被选中一个
   * @param string radioName
   */
  function radioChecked(radioName)
  {
    var eles = document.forms['theForm'].elements;

    for (var i = 0; i < eles.length; i++)
    {
      if (eles[i].name == radioName && eles[i].checked)
      {
        return true;
      }
    }
    return false;
  }

  /**
   * 按用户编号或用户名搜索用户
   */
  function searchUser()
  {
    var eles = document.forms['theForm'].elements;

    /* 填充列表 */
    var idName = Utils.trim(eles['keyword'].value);
    if (idName != '')
    {
      Ajax.call('order.php?act=search_users&id_name=' + idName, '', searchUserResponse, 'GET', 'JSON');
    }
  }

  function searchUserResponse(result)
  {
    if (result.message.length > 0)
    {
      alert(result.message);
    }

    if (result.error == 0)
    {
      var eles = document.forms['theForm'].elements;

      /* 清除列表 */
      var selLen = eles['user'].options.length;
      for (var i = selLen - 1; i >= 0; i--)
      {
        eles['user'].options[i] = null;
      }
      var arr = result.userlist;
      var userCnt = arr.length;

      for (var i = 0; i < userCnt; i++)
      {
        var opt = document.createElement('OPTION');
        opt.value = arr[i].user_id;
        opt.text = arr[i].user_name;
        eles['user'].options.add(opt);
      }
    }
  }

  /**
   * 按商品编号或商品名称或商品货号搜索商品
   */
  function searchGoods()
  {
    var eles = document.forms['goodsForm'].elements;

    /* 填充列表 */
    var keyword = Utils.trim(eles['keyword'].value);
    if (keyword != '')
    {
      Ajax.call('order.php?act=search_goods&keyword=' + keyword, '', searchGoodsResponse, 'GET', 'JSON');
    }
  }

  function searchGoodsResponse(result)
  {
    if (result.message.length > 0)
    {
      alert(result.message);
    }

    if (result.error == 0)
    {
      var eles = document.forms['goodsForm'].elements;

      /* 清除列表 */
      var selLen = eles['goodslist'].options.length;
      for (var i = selLen - 1; i >= 0; i--)
      {
        eles['goodslist'].options[i] = null;
      }

      var arr = result.goodslist;
      var goodsCnt = arr.length;
      if (goodsCnt > 0)
      {
        for (var i = 0; i < goodsCnt; i++)
        {
          var opt = document.createElement('OPTION');
          opt.value = arr[i].goods_id;
          opt.text = arr[i].name;
          eles['goodslist'].options.add(opt);
        }
        getGoodsInfo(arr[0].goods_id);
      }
      else
      {
        getGoodsInfo(0);
      }
    }
  }

  /**
   * 取得某商品信息
   * @param int goodsId 商品id
   */
  function getGoodsInfo(goodsId)
  {

    if (goodsId > 0)
    {
      Ajax.call('order.php?act=json&func=get_goods_info&order_id={$order_id}', 'goods_id=' + goodsId, getGoodsInfoResponse, 'get', 'json');
 
    }
    else
    {
      document.getElementById('goods_name').innerHTML = '';
      document.getElementById('goods_sn').innerHTML = '';
      document.getElementById('goods_cat').innerHTML = '';
      document.getElementById('goods_brand').innerHTML = '';
      document.getElementById('add_price').innerHTML = '';
      document.getElementById('goods_attr').innerHTML = '';
    }
  }
  function getGoodsInfoResponse(result)
  {    
        $('#order_goods_info').html('');
        $('#order_goods_info').html(result);
  }

  /**
   * 把商品加入订单
   */
  function addToOrder()
  {
    var eles = document.forms['goodsForm'].elements;

    // 检查是否选择了商品
    if (eles['goodslist'].options.length <= 0)
    {
      alert(pls_search_goods);
      return false;
    }

    var goods_id = $("#goodslist").val();
    var goods_price =$("#add_price").find('input:radio[name="add_price"]:checked').val();
    if(goods_price == "user_input" ){
      goods_price=$("input:text[name='input_price'] ").val();
    }
    var goods_number = $("input:text[name='add_number'] ").val();
    var compose_note = $("input:hidden[name='compose_note'] ").val();

    if($("#goods_attr").length>0){
      var attr = {};
      $("#goods_attr").find('div').each(function(){
        var num=$(this).find('input').val();
        var sku = $(this).find('input').attr('sku');
        if(num >0){
         attr[sku]=num;
        }
      });
    }
    var goods_info =
    {
      'goods_id': goods_id,           //商品ID
      'goods_number': goods_number,       //商品数量
      'goods_price':goods_price,       //商品价格
      'compose_note':compose_note,       //最组合信息 
    };
    Ajax.call('order.php?act=step_post&step=add_goods&order_id={$order_id}&step_act={$step_act}', 'attr='+JSON.stringify(attr)+'&goods_info=' +JSON.stringify(goods_info), addToOrderResponse, 'POST', 'JSON');
    return false;
  }
  function addToOrderResponse(data)
  {
    // alert(JSON.stringify(data));
   if(data.error == 0){
      alert(data.content);
   }
   if(data.error == 1){
    $('#order_goods').html("");
    $('#order_goods').html(data.content);
   }

  }


  /**
   * 载入收货地址
   * @param int addressId 收货地址id
   */
  function loadAddress(addressId)
  {
{/literal}
    location.href += 'order.php?act={$smarty.get.act}&order_id={$smarty.get.order_id}&step={$smarty.get.step}&address_id=' + addressId;
{literal}
  }
</script>
{/literal}

{include file="pagefooter.htm"}